<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/26
 * Time: 13:55
 */

namespace App\Http\Controllers\Doctor;

use App\Http\Controllers\ApiController;
use App\LogicService\Contracts\HospitalManageLogicContract;
use App\Models\UserBase;
use Illuminate\Http\Request;

class DoctorController extends ApiController
{

    protected $request;

    protected $hospitalManage;

    public function __construct(Request $request, HospitalManageLogicContract $hospitalManage)
    {
        parent::__construct();
        $this->request = $request;
        $this->hospitalManage = $hospitalManage;

    }


    public function getDoctorListByHospital()
    {
        $this->validate($this->request, [
            'hospital_id' => 'integer',
        ]);

        $user = \Auth::user();
        $hospital_id = $this->request->input('hospital_id');
        if (!$hospital_id) {
            $hospital_id = $user->hospital_id;
        }
        $hospital_ids[] = $hospital_id;

        $user_type = $user->type;
        $intype = [];
        switch ($user_type) {
            case 0:
                $intype = ['2', '3', '4'];
                break;
            case 3:
                $intype = ['2', '3'];
                break;
            case 4:
                $intype = ['2', '3', '4'];
                break;
        }

        $doctor_list = UserBase::whereIn('hospital_id', $hospital_ids)
            ->select('id', 'name')
            ->orderBy('id', 'desc')
            ->whereIn('type', $intype)
            ->get()
            ->toArray();

        return $this->response($doctor_list);

    }


}